<template>
  <div class="form-container">
    <el-form ref="form" :model="form" label-width="80px" :line="true" class="form">
      <div style="display:flex;">
        <el-form-item label="姓名">
          <el-input v-model="form.query" />
        </el-form-item>
        <el-form-item label="所属组织">
          <el-cascader
            v-model="selected_client_Options"
            style="width: 300px;"
            :options="cleint_options"
            clearable
            :props="cleint_props"
            change-on-select
            @change="client_handleChange"
          />
        </el-form-item>
        <el-form-item label="角色">
          <el-select v-model="form.roleId" placeholder="角色" :clearable="true">
            <el-option
              v-for="item in rolesList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
      </div>
      <div style="display:flex;">
        <el-form-item label="用户名">
          <el-input v-model="form.username" />
        </el-form-item>
        <el-form-item label="分组">
          <el-select
            v-model="form.groupId"
            placeholder="分组"
            :clearable="true"
            @change="chage_select_group"
          >
            <el-option
              v-for="item in userGroups"
              :key="item.id"
              :label="item.name"
              :value="item.id+''"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="上级用户">
          <el-select v-model="form.parentId" placeholder="上级用户" :clearable="true">
            <el-option
              v-for="item in parentUsers"
              :key="item.id"
              :label="item.name"
              :value="item.id+''"
            />
          </el-select>
        </el-form-item>
      </div>
      <div>
        <el-form-item>
          <el-button type="primary" @click="onSubmit">搜索</el-button>
          <el-button @click="reset('from')">重置</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
// import { GET_clientsSel } from '@/api/common'
// import { mapState, mapActions } from 'vuex'
// import { GET_ROLES, GET_ACCOUNT } from '../../../api/common'
// import { GET_clients } from '../../../api/orgManage'
// import { getRequestParam } from '../../../utils/dom'
// import { get_userGroups_for_select } from '../../../api/privilegeManagement'
export default {
  name: 'FormContainer',
  props: ['label'],
  data() {
    return {
      form: {
        query: '',
        clientId: '',
        username: '',
        roleId: '',
        // groupId: getRequestParam(document.location.href, 'groupId'),
        parentId: ''
      },
      selectOptionValue: [],
      options: [],
      selected_client_Options: [],
      rolesList: [],
      cleint_options: [],
      cleint_props: {
        value: 'id',
        label: 'name',
        children: 'subs'
      },
      userGroups: [],
      parentUsers: []
    }
  },
  //   computed: {
  //     ...mapState({})
  //   },
  //   watch: {
  //     selectOptionValue: function(newValue) {
  //       this.formInline.clientId = newValue[newValue.length - 1]
  //     }
  //   },
  //   mounted() {
  //     var groupId = getRequestParam(document.location.href, 'groupId')
  //     if (groupId) {
  //       this.form.groupId = groupId + ''
  //     }
  //     this.getRolesList()
  //     GET_clients().then(res => {
  //       this.form.clientId = res[0].id
  //       this.cleint_options = res
  //     })
  //     get_userGroups_for_select().then(res => {
  //       this.userGroups = res
  //     })
  //     GET_ACCOUNT().then(res => {
  //       this.parentUsers = res
  //     })
  //   },

  methods: {
  //     ...mapActions(['getDeviceGroups']),
    chage_select_group(e) {},
    //     // 确定选择了组织
    //     client_handleChange(val) {
    //       this.form.clientId = val[val.length - 1]
    //     },
    //     getRolesList() {
    //       GET_ROLES().then(res => {
    //         this.rolesList = res
    //       })
    //     },
    onSubmit() {
      console.log(1111)
      //       this.$emit('submit', this.form)
    },
    reset() {
      console.log('cz')
    //       this.form = {
    //         name: ''
    //       }
    //       this.selectOptionValue = []
    //       this.$emit('resetForm')
    }
    //     findNodePath(parentIds, node, targetId) {
    //       if (node.value === targetId) {
    //         parentIds.push(targetId)
    //         return parentIds
    //       }
    //       if (node.children && node.children.length > 0) {
    //         parentIds.push(node.value)

    //         for (let i = 0; i < node.children.length; i++) {
    //           const sub = node.children[i]
    //           const result = this.findNodePath(parentIds, sub, targetId)
    //           if (result) {
    //             return parentIds
    //           }
    //         }
    //         parentIds.splice(parentIds.length - 1, 1)
    //       }
    //     }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.form-container {
  padding: 20px;
  background: #fff;
}
</style>
